#pragma execution_character_set("utf-8")
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <string>
#include <limits>
#include "fuction4.h"
#include "fuction5.h"
#include "fuction6.h"
#include "fuction7.h"
#include "fuction8_1.h"
#include "fuction8_2.h"
#include "fuction3.h"
#include "fuction1_1.h"
extern "C" {
#include "LunarSolarConverter.h"
}
using namespace std;
int aaa = 7;  // 白色
int aab = 0;  // 黑色
// 获取当前时间字符串
string bbb() {
    SYSTEMTIME st;
    GetLocalTime(&st);
    char aac[20];
    sprintf(aac, "%04d-%02d-%02d %02d:%02d:%02d",
            st.wYear, st.wMonth, st.wDay,
            st.wHour, st.wMinute, st.wSecond);
    return string(aac);
}
// 设置控制台文字颜色（前景色+背景色）
void bbc(int aad, int aae) {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, (WORD)((aae << 4) | aad));
}
void bbd(){
    int f,b;
    cout << "颜色代码参考:" << endl;
    cout << "0: 黑色    1: 蓝色    2: 绿色    3: 青色    4: 红色" << endl;
    cout << "5: 紫色    6: 黄色    7: 白色    8: 灰色    9: 粉色" << endl;
    cout << "请输入前景色代码 (0~9): ";
    cin >> f;
    cout << "请输入背景色代码 (0~9): ";
    cin >> b;

    if (f < 0 || f > 9 || b < 0 || b > 9) {
        cout << "暂不支持该颜色，已使用默认颜色。" << endl;
        f = 7;
        b = 0;
    }

    // 设置全局变量颜色值
    aaa = f;
    aab = b;
    cout << "颜色设置完成，按任意键继续..." << endl;
    _getch();
}
void bbe() {
    system("cls");

    // 设置菜单颜色
    bbc(aaa, aab);
    cout << "=================== 万年历应用 ===================" << endl;

    // 当前时间行（红色字）
    bbc(12, aab);
    cout << "   当前时间: " << bbb() << endl;

    bbc(aaa, aab);
    cout << "================================================" << endl << endl;

    cout << "1. 查询农历" << endl;
    cout << "2. 查询公历" << endl;
    cout << "3. 显示月历" << endl;
    cout << "4. 查询某天距离今天的天数" << endl;
    cout << "5. 查询距今天相应天数的日期" << endl;
    cout << "6. 查询任何两天之间的天数差" << endl;
    cout << "7. 显示24节气" << endl;
    cout << "8. 显示节日" << endl;
    cout << "c. 自定义菜单颜色" << endl;
    cout << "0. 退出程序" << endl << endl;

    cout << "请选择功能（按对应数字或字母）：";
}
int main() {
    
    SetConsoleOutputCP(CP_UTF8);
    SetConsoleCP(CP_UTF8);
    // 主循环
    while (true) {
        bbe();
        char ch = _getch();
        cout << ch << endl;
        switch (ch) {
            case '1':{
            fuction1_1 q;
            q.Query();
            break;
            }
            case '2':{
                int y,m,d; char le;
                cout<<"输入农历(年 月 日): ";
                cin>>y>>m>>d;
                cout<<"你要查询的是闰某月还是某月? (y/n): "; cin>>le;
                Lunar l = { (le=='y'), d, m, y }; 
                Solar s = LunarToSolar(l);
                cout<<"\n对应公历: "<<s.solarYear<<"-"
                    <<s.solarMonth<<"-"<<s.solarDay<<"\n";
                cout<<"\n按任意键返回..."; _getch();
                break;
            }
            case '3':{
                fuction3 calc;
                calc.show();
                break;

            }
            case '4':{
                fuction4 calc;
                calc.Calculate();
                break;
            }
            case '5':{
                fuction5 calc;
                calc.Calculate();
                break;
            }
            case '6':{
                fuction6 calc;
                calc.Calculate();
                break;
            }
            case '7':{
                fuction7 terms;
                terms.Display();
                break;
            }
            case '8':{
                int choice;
                cout << "\n请选择节日类型： \n";
                cout << "1.公历节日\n";
                cout << "2.农历节日\n";
                cout << "你的选择是：";
                cin >> choice;

                if(choice==1){
                    int month;
                    cout << "\n请输入你要查询的月份：";
                    cin >> month;
                    fuction8_1 solar;
                    solar.jieri_yue(month);
                }else if (choice==2){
                    fuction8_2 lunar;
                    lunar.jieri();
                }else{
                    cout << "输入无效，请输入1或者2。\n";
                }
                break;
            }
            case 'c':
                bbd();
                break;
            case '0':
                cout << "退出程序..." << endl;
                return 0;
            default:
                cout << "无效的选择，请按任意键继续..." << endl;
                _getch();
                break;
        }
    }
    return 0;
}
